package com.jprocms.module.cms.convert.channel;

import com.jprocms.module.cms.dal.dataobject.channel.ChannelAttrDO;
import com.jprocms.module.cms.dal.dataobject.model.ModelDO;
import com.jprocms.module.cms.util.ModelWrapper;
import org.mapstruct.Mapper;
import org.mapstruct.factory.Mappers;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

/**
 * 栏目自定义字段 Convert
 *
 * @author jprocms
 */
@Mapper
public interface ChannelAttrConvert {

    ChannelAttrConvert INSTANCE = Mappers.getMapper(ChannelAttrConvert.class);

    default List<ChannelAttrDO> disassembleCustoms(ModelDO model, Long id, Map<String, Object> customs) {
        List<ChannelAttrDO> list = new ArrayList<>();
        ModelWrapper modelWrapper = new ModelWrapper(model);
        modelWrapper.disassembleCustoms(customs, (name, type, value) -> list.add(new ChannelAttrDO(id, name, type, value)));
        return list;
    }

}
